package com.ruoyi.web.controller.dy;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.domain.entity.TlDyCategory;
import com.ruoyi.system.service.ITlDyCategoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 抖音类目Controller
 *
 * @author ruoyi
 * @date 2023-10-21
 */
@RestController
@RequestMapping("/system/category")
public class TlDyCategoryController extends BaseController
{
    @Autowired
    private ITlDyCategoryService tlDyCategoryService;

    /**
     * 查询抖音类目列表
     */
    @GetMapping("/list")
    public AjaxResult list(TlDyCategory tlDyCategory)
    {
        List<TlDyCategory> list = tlDyCategoryService.selectTlDyCategoryList(tlDyCategory);
        return success(list);
    }

    /**
     * 导出抖音类目列表
     */
    @Log(title = "抖音类目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TlDyCategory tlDyCategory)
    {
        List<TlDyCategory> list = tlDyCategoryService.selectTlDyCategoryList(tlDyCategory);
        ExcelUtil<TlDyCategory> util = new ExcelUtil<TlDyCategory>(TlDyCategory.class);
        util.exportExcel(response, list, "抖音类目数据");
    }

    /**
     * 获取抖音类目详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tlDyCategoryService.selectTlDyCategoryById(id));
    }

    /**
     * 新增抖音类目
     */
    @Log(title = "抖音类目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TlDyCategory tlDyCategory)
    {
        return toAjax(tlDyCategoryService.insertTlDyCategory(tlDyCategory));
    }

    /**
     * 修改抖音类目
     */
    @Log(title = "抖音类目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TlDyCategory tlDyCategory)
    {
        return toAjax(tlDyCategoryService.updateTlDyCategory(tlDyCategory));
    }

    /**
     * 删除抖音类目
     */
    @Log(title = "抖音类目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tlDyCategoryService.deleteTlDyCategoryByIds(ids));
    }

    /**
     * 获取抖音类目下拉树列表
     */
    @GetMapping("/treeselect")
    public AjaxResult treeselect(TlDyCategory tlDyCategory)
    {
        List<TlDyCategory> tlDyCategories = tlDyCategoryService.selectTlDyCategoryList(tlDyCategory);
        return success(tlDyCategoryService.buildCategoryTreeSelect(tlDyCategories));
    }

    @PostMapping("/dataSync")
    public AjaxResult syncDyCategory(){
        tlDyCategoryService.syncDyCategory();
        return null;
    }
}
